home *** CD-ROM | disk | FTP | other *** search
- { psetup.pas -- Demonstrate Printer setup dialog }
-
- program PSetup;
-
- {$R psetup.res}
-
- uses WinTypes, WinProcs, WObjects, Strings, UPrint;
-
- const
-
- id_Menu = 100; { Menu resource ID }
- cm_Setup = 101; { Menu:Printer setup... command ID }
- cm_Quit = 102; { Menu:Exit command ID }
-
- type
-
- PSetupApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PPSetupWindow = ^PSetupWindow;
- PSetupWindow = object(TWindow)
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- procedure CMSetup(var Msg: TMessage);
- virtual cm_First + cm_Setup;
- procedure CMQuit(var Msg: TMessage);
- virtual cm_First + cm_Quit;
- end;
-
- TDeviceMode = procedure(HWindow: HWnd; Module: THandle;
- DeviceName, OutputName: PChar);
-
- TExtDeviceMode =
- function(HWindow: HWnd; HDriver: THandle; DevModeOutput: PDevMode;
- DeviceName, OutputName: PChar; DevModeInput: PDevMode;
- Profile: PChar; Mode: Word): Integer;
-
-
- { PSetupApplication }
-
- {- Initialize PSetupApplication object's window }
- procedure PSetupApplication.InitMainWindow;
- begin
- MainWindow := New(PPSetupWindow, Init(nil, 'PSetup'))
- end;
-
-
- { PSetupWindow }
-
- {- Construct PSetupWindow object }
- constructor PSetupWindow.Init(AParent: PWindowsObject; ATitle: PChar);
- begin
- TWindow.Init(AParent, ATitle);
- Attr.Menu := LoadMenu(HInstance, PChar(id_Menu));
- end;
-
- var
- ExtDeviceMode: TExtDeviceMode;
- DeviceMode: TDeviceMode;
-
- {- Execute Menu:Printer setup... command }
- procedure PSetupWindow.CMSetup(var Msg: TMessage);
- var
- HDriver: THandle;
- Size: Integer; { Size of DevMode structure }
- DeviceName, DriverName, OutputName: PChar;
- DriverExtName: array[0 .. 12] of Char;
- Buffer: array[0 .. 80] of Char;
- DevModeOutput: PDevMode;
- P: TFarProc;
- begin
- GetProfileString('windows', 'device', ',,', Buffer, Sizeof(Buffer));
- DeviceName := NextToken(Buffer, ',');
- DriverName := NextToken(nil, ',');
- OutputName := NextToken(nil, ',');
- if (StrLen(DeviceName) = 0) or
- (StrLen(DriverName) = 0) or (StrLen(OutputName) = 0) then
- begin
- MessageBox(HWindow, 'No printer installed', 'Error', mb_Ok);
- Exit
- end;
- StrLCat(StrCopy(DriverExtName, DriverName), '.DRV', 12);
- HDriver := LoadLibrary(DriverExtName);
- if HDriver < 32 then
- MessageBox(HWindow, 'Failed to load driver', 'Error',
- mb_IconExclamation or mb_Ok)
- else begin
- P := GetProcAddress(HDriver, 'ExtDeviceMode');
- if P <> nil then
- begin
- ExtDeviceMode := TExtDeviceMode(P);
- Size := ExtDeviceMode(HWindow, HDriver, nil, DeviceName,
- OutputName, nil, nil, 0);
- GetMem(DevModeOutput, Size);
- ExtDeviceMode(HWindow, HDriver, DevModeOutput, DeviceName,
- OutputName, nil, nil, dm_Prompt or dm_Copy);
- FreeMem(DevModeOutput, Size)
- end else
- begin
- P := GetProcAddress(HDriver, 'DeviceMode');
- if P <> nil then
- begin
- DeviceMode := TDeviceMode(P);
- DeviceMode(HWindow, HDriver, DeviceName, OutputName)
- end
- end;
- FreeLibrary(HDriver)
- end;
- end;
-
- {- Execute Menu:Exit command }
- procedure PSetupWindow.CMQuit(var Msg: TMessage);
- begin
- CloseWindow
- end;
-
- var
-
- PSetupApp: PSetupApplication;
-
- begin
- PSetupApp.Init('PSetupApp');
- PSetupApp.Run;
- PSetupApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 5/22/1991
- ---------------------------------------------------------------}
-